<?php
/**
* ajax服务类
* @author  卢绍明
* @date    2017-12-17
*/
namespace  App\Http\Services;
class AjaxService{
    public static $return_code = array(
        'SUCCESS'           =>array('code'=>'0','msg'=>'成功'),
        'FAIL'              =>array('code'=>'-1','msg'=>'失败'),
        'EMPTY_PARAMETER'   =>array('code'=>'-30001','msg'=>'参数不能为空'),
        'ERROR_CODE'        =>array('code'=>'-30002','msg'=>'验证码不正确'),
        'LOGIN_FAIL'        =>array('code'=>'-30003','msg'=>'账号不存在或密码错误'),
        'TYPE_ERROR'        =>array('code'=>'-30004','msg'=>'图片格式错误'),
        'MAX_SIZE_LIMIT'    =>array('code'=>'-30004','msg'=>'上传文件超出最大限制'),
        'NO_IMAGE_ERROR'    =>array('code'=>'-30005','msg'=>'请选择一张图片'),
        'EMPTY_TITLE'       =>array('code'=>'-30006','msg'=>'标题不能为空'),
        'EMPTY_CONTENT'     =>array('code'=>'-30007','msg'=>'内容不能为空'),
        'EMPTY_TAGS'        =>array('code'=>'-30008','msg'=>'标签不能为空'),
        'INVALID_TOKEN'     =>array('code'=>'-30009','msg'=>'无效的access_token'),
        'TIME_EXPIRE'       =>array('code'=>'-30010','msg'=>'请求已过期'),
        'ERROR_OPENID'      =>array('code'=>'-30010','msg'=>'openid无效'),
        'INVALID_USER'      =>array('code'=>'-30011','msg'=>'该用户已被禁用'),
        'INVALID_AUTO_LOGIN_TOKEN' => array('code'=>'-30012','msg'=>'无效的token'),
        'AUTO_LOGIN_SUCCESS' => array('code'=>'0','msg'=>'自动登录成功'),
        'USER_NOT_EXIST' => array('code'=>'0','msg'=>'用户不存在'),
        
    );
    /**
     * ajax返回格式
     * @param array $return 状态及提示信息
     * @param array $data   数据，如果需要的话
     */
    public static function ajax_return($return,$data=array())
    {
        $code = 200;
        if (isset($return['error'])) {
            $code = 400;
            $msg = $return['error'];
        } else {
            $msg = $return['msg'];
        }
        $return_data['status'] = $code;
        $return_data['msg'] = $msg;
        $return_data['data'] = $data;

        echo json_encode($return_data);
        exit;
    }
}